﻿
@{
    ViewBag.Title = "注册 - 咕嘟咕嘟";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
}
@section head{
    <link href="~/static/css/layui.css" rel="stylesheet" />
    <script src="/js/jquery-1.11.3.min.js"></script>
    <script src="~/static/layui.js"></script>

}


@section blurWrap{
    <div class="blurWrap" id="shop">
}
<!--首页banner开始-->
<div class="timeLimit">
    <h2>注册</h2>
    <hr>
    
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">账号</label>
            <div class="layui-input-inline">
                <input type="text" name="uname" required lay-verify="required" placeholder="将来登录用的账号" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-inline">
                <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
            </div>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-inline">
                <input type="text" name="mobile" required id="phone" lay-verify="phone" placeholder="找回密码的凭证" autocomplete="off" class="layui-input">
            </div>
        </div>
        @*<div class="layui-form-item">
            <label class="layui-form-label">验证码</label>
            <div class="layui-input-inline">
                <input type="text" name="code" required lay-verify="required" placeholder="输入手机接收到的验证码" autocomplete="off" class="layui-input">

            </div>
            <div class="layui-form-mid">
                <button id="getCode" class="layui-btn layui-btn-small layui-btn-normal layui-btn-radius">获取验证码</button>
                <input type="button" id="getCode" class="layui-btn layui-btn-small layui-btn-normal layui-btn-radius" value="获取验证码" />
            </div>
        </div>*@
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="register">立即注册</button>

            </div>
        </div>

    </form>


</div>
<!--首页banner结束-->


<script>
    layui.use("form", function () {
        var form = layui.form();
        form.on('submit(register)', function (data) {
            //console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
            //console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
            //console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
            //layer.msg(JSON.stringify(data.field));

            uname = data.field.uname;
            pass = data.field.password;
            mobile = data.field.mobile;
            //code = data.field.code;
            $.post("/User/Register", { uname: uname, pwd: pass, mobile: mobile }, function (data) {

                if (data.resCode != 200) {
                    layer.alert(data.resMsg)
                } else {
                    layer.alert(data.resMsg, function (index) {
                        layer.close(index)
                        location.href = "/"
                    })
                    
                }
            }, "json")
            return false;
        });


        form.on("switch(auto_login)", function (data) {
            if (data.elem.checked) {
                auto_login = true;
            } else {
                auto_login = false;
            }
        })

    })
    $("#getCode").click(function () {
        phone = $("#phone").val()
        if (phone == "") {
            layer.msg("请输入手机号", { icon: 5 })
            return;
        } else {
            var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
            if (!myreg.test(phone)) {
                layer.msg('请输入有效的手机号码！', { icon: 5 });
                return false;
            }
        }
        $.post("/User/GetCode", { phone: phone }, function (data) {
            if (data.resCode != 200) {
                layer.alert(data.resMsg)
            } else {
                layer.msg(data.resMsg)

            }
        }, "json")
    })

</script>

